package br.com.center.loja.ws.dto.converter;

import java.util.ArrayList;
import java.util.List;

import br.com.center.loja.model.Product;
import br.com.center.loja.ws.dto.ProductDTO;
 
public class ProductDTOConverter implements Converter<Product, ProductDTO>{

	@Override
	public ProductDTO to(Product element) {
		return new ProductDTO(element);
	}

	@Override
	public Product from(ProductDTO element) {
		Product product = new Product();
		product.setCode(element.getCode());
		product.setMinStock(element.getMinStock());
		product.setModel(element.getModel());
		product.setName(element.getName());
		product.setPrice(element.getPrice());
		product.setStock(element.getStock());
		return product;
	}

	@Override
	public List<ProductDTO> to(List<Product> elements) {
		List<ProductDTO> result = new ArrayList<ProductDTO>();
		
		for(Product element : elements){
			result.add(to(element));
		}
		
		return result;
	}

	@Override
	public List<Product> from(List<ProductDTO> elements) {
		List<Product> result = new ArrayList<Product>();
		
		for(ProductDTO element : elements){
			result.add(from(element));
		}
		
		return result;
	}

}
